package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface AlbumInfoMapper extends BaseMapper<AlbumInfo> {

    /**
     * 分页查询专辑列表
     * @param page 它会通过mybatis-plus 分页插件自动将分页条件追加到sql语句末尾! 原理拦截器
     * @param albumInfoQuery
     * @return
     */
    IPage<AlbumListVo> selectUserAlbumPage(Page<AlbumListVo> page, @Param("vo") AlbumInfoQuery albumInfoQuery);

    /**
     * 根据专辑id获取专辑统计信息
     * @param albumId
     * @return
     */
    AlbumStatVo getAlbumStat(Long albumId);

    /**
     * 更新专辑统计信息
     * @param count
     * @param albumId
     * @param statPlay
     */
    @Update("update album_stat set stat_num = stat_num + #{count} where album_id = #{albumId} and stat_type = #{statPlay} and is_deleted = 0")
    int updateAlbumStat(@Param("count") Integer count, @Param("albumId") Long albumId, @Param("statPlay") String statPlay);
}
